package com.uit.httt04.duongvanlam.facedetection.utils;

import android.annotation.SuppressLint;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

@SuppressLint("SimpleDateFormat")
public class ClassLogger
{
	public static void Write(String className, String methodName, String text)
	{
		try
		{
			// <-- Create logger's folder
			File folderLog = new File(Configuration.logFolderPath);
			if (folderLog.exists() == false)
				folderLog.mkdirs();
			// Create logger's folder -->
			// <-- Create logger's file
			File fileLog = new File(folderLog, Configuration.logFileName);
			if (fileLog.exists() == false)
				fileLog.createNewFile();
			// Create logger's file -->
			SimpleDateFormat dateFormat = new SimpleDateFormat(Configuration.SimpleDateFormatPattern);
			BufferedWriter buf = new BufferedWriter(new FileWriter(fileLog, true));
			// <-- Write
			buf.append("------");
			buf.newLine();
			buf.append("Date: " + dateFormat.format(new Date()));
			buf.newLine();
			buf.append("Class: " + className);
			buf.newLine();
			buf.append("Method: " + methodName);
			buf.newLine();
			buf.append("Error: " + text);
			buf.newLine();
			buf.append("------");
			buf.newLine();
			buf.newLine();
			// Write -->
			buf.close();
		}
		catch (IOException iOException)
		{
			iOException.printStackTrace();
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
